package com.ndood.reconciliation.app.redis;

import org.springframework.stereotype.Service;

import com.ndood.reconciliation.base.enums.EnumPayway;
import com.ndood.reconciliation.base.pojo.ReconInfo;

@Service
public class RedisReconKeyHelper {
	
	public static final String KEY_STORE_SNAPCHAT = "recon-snapchat";
	
	public static final String KEY_STORE = "recon";
	
	public final String PERFIX_ALIPAY = "alipay-reconciliation";
	
	public final String PERFIX_WECHAT = "wechat-reconciliation";
	
	public final String PERFIX_UNION = "union-reconciliation";
	
	public String alipayReconKey(String batchNo) {
		return String.format("%s:%s", PERFIX_ALIPAY, batchNo);
	}

	public String wechatReconKey(String batchNo) {
		return String.format("%s:%s", PERFIX_WECHAT, batchNo);
	}
	
	public String unionReconKey(String batchNo) {
		return String.format("%s:%s", PERFIX_WECHAT, batchNo);
	}

	/**
	 * 根据key获取对账记录
	 */
	public ReconInfo getReconInfo(String reconKey) {
		ReconInfo reconInfo = new ReconInfo();
		EnumPayway enumReconType;
		String batchNo;
		if (reconKey.startsWith(PERFIX_ALIPAY)) {
			enumReconType = EnumPayway.ALIPAY;
			batchNo = reconKey.substring(PERFIX_ALIPAY.length());
		} else if (reconKey.startsWith(PERFIX_WECHAT)) {
			enumReconType = EnumPayway.WECHAT;
			batchNo = reconKey.substring(PERFIX_WECHAT.length());
		} else if (reconKey.startsWith(PERFIX_UNION)) {
			enumReconType = EnumPayway.UNION;
			batchNo = reconKey.substring(PERFIX_UNION.length());
		}
		else {
			enumReconType = EnumPayway.INVALID;
			batchNo = null;
		}
		reconInfo.setBatchNo(batchNo);
		reconInfo.setReconType(enumReconType);
		return reconInfo;
	}
}